#include<iostream>
#include<fstream>
#include"contacts.pb.h"
using namespace std;
void AddPeopleInfo(s_contacts::PeopleInfo*people)
{
    cout << "-------------新增联系人-------------" << endl;
    cout << "请输入联系人姓名: ";
    string name;
    getline(cin, name);
    people->set_name(name);
    cout << "请输入联系人生日: ";
    int birthday;
    cin >> birthday;
    people->set_birthday(birthday);
    cin.ignore(256, '\n');

    cout << "-----------添加联系人成功-----------" << endl;
}
int main()
{
    s_contacts::Contacts contacts;
    fstream input("../client/1.bin",ios::in | ios::binary); 
    if(!input)
    {
        cout<<"1.bin not find,create new file"<<endl;
    }
    else if(!contacts.ParseFromIstream(&input))
    {
        cerr<<"parse error!"<<endl;
        input.close();
        return -1;
    }
    AddPeopleInfo(contacts.add_contacts());
    fstream output("../client/1.bin",ios::out | ios::trunc | ios::binary);
    if(!contacts.SerializeToOstream(&output))
    {
        cerr<<"write error!"<<endl;
        input.close();
        output.close();
        return -1;
    }
    cout<<"write success"<<endl;
    input.close();
    output.close();
    return 0;

}